package com.zx.idc.backend.gui.scheduler.ins.filtermonitorlog.job.base;

import com.zx.idc.backend.gui.sys.login.MailClient;
import com.zx.idc.common.spring.SpringBeanUtil;
import com.zx.idc.ds.tlog.entity.TLogAlarm;
import com.zx.idc.ds.tlog.factory.TLogAlarmFactory;
import com.zx.idc.ds.tlog.service.ITLogAlarmService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseFilterAndMonitorInstructionJob {

    private static final Logger LOG = LoggerFactory.getLogger(BaseFilterAndMonitorInstructionJob.class);

    @Autowired
    private MailClient mailClient;

    protected void addTLogAlarm(String source, String msg) {
        //添加到告警表
        try {
            ITLogAlarmService itLogAlarmService = SpringBeanUtil.getBean(ITLogAlarmService.class);
            TLogAlarm tLogAlarm = TLogAlarmFactory.getCallingInternalInterfaceFailed(msg);
            itLogAlarmService.insert(tLogAlarm);
            mailClient.sendAlarmEmail("有新的告警日志生成，来自" + source, "具体请查看ID为" + tLogAlarm.getId() + "的告警日志。");
        }catch(Exception e){
            LOG.error(String.format("Record and send alarm fail, error message as: %s", e.getMessage()), e);
        }
    }
}
